/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.gui.documents.toolbox;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import math.Relation;
import model.AltaRicaConst;
import model.AltaRicaDomain;
import model.altarica_fields.Event;
import model.altarica_fields.Sync;
import model.altarica_fields.Trans;
import model.altarica_fields.Var;
import parser.AltaRicaParseNode;

/**
 *
 * @author stephane
 */
public class AltaRicaTreeRender extends DefaultTreeCellRenderer {
    private static final long serialVersionUID = 1L;


    public AltaRicaTreeRender() {
       
    }

    @Override
    
    
    public Component getTreeCellRendererComponent(JTree tree, Object value,boolean sel,boolean expanded, boolean leaf,int row, boolean hasFocus) 
    {
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        if (value instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
            if (node.isRoot()) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaIcon.png")));
            }
            else if (node.getLevel() == 1 && !(node.getUserObject() instanceof Relation)) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/package.png")));
            }
            else if (node.getUserObject() instanceof Relation) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/relation.png")));
            }
            else if (node.getUserObject() instanceof AltaRicaParseNode) {
                setText(((AltaRicaParseNode)node.getUserObject()).getName());
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaNode.png")));
            }
            else if (node.getUserObject() instanceof AltaRicaDomain) {
                setText(((AltaRicaDomain)node.getUserObject()).getName());
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaDomain.png")));
            }
            else if (node.getUserObject() instanceof AltaRicaConst) {
                setText(((AltaRicaConst)node.getUserObject()).toString());
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaConst.png")));
            }
            else if (node.getUserObject() instanceof Trans) {
                setText(((Trans)node.getUserObject()).toString());
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaTrans.png")));
            }
            else if (node.getUserObject() instanceof Var && !((Var)node.getUserObject()).isStateVar()) {
                setText(((Var)node.getUserObject()).getId()+ " : " + ((Var)node.getUserObject()).getType().toString());
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaFlow.png")));
            }
            else if (node.getUserObject() instanceof Var && ((Var)node.getUserObject()).isStateVar()) {
                setText(((Var)node.getUserObject()).getId()+ " : " + ((Var)node.getUserObject()).getType().toString());
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaState.png")));
            }
            else if (node.getUserObject() instanceof Event) {
                
                Event e = ((Event)node.getUserObject());                
		setText(e.getId());
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaEvent.png")));
            }
            else if (node.getUserObject() instanceof Sync) {
                
                Sync s = ((Sync)node.getUserObject());     
                String str = "";
                for (Sync.SyncElement item : s.getSyncs()) {
                    str += item.toString() + ", ";
                }
                str = str.substring(0, str.length() - 2);
		setText(str);
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/altaricaSynchro.png")));
            }
        }
    
        return this;
    }
}
